<template>
  <div>
    <el-dialog :title="flagval.title=='day'?'日预算电量':'小时预算电量'" :visible.sync="dialogVisible" width="70%">
      <div>
        <div style="margin-bottom: 10px;">
          <el-button size="small" type="primary" @click="exporttab"
            >导 出</el-button
          >
        </div>
        <div>
          <TableColumn
            ref="tabledataref"
            :tableData="tableData"
            :tableConfig="tableConfig"
          />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { exportexcel } from '@/utils/excel'
import TableColumn from '@/components/Table/index.vue'
import {getDayReportapi,getHourReportapi} from '@/api/energy-consumption/demand/budget-team'
export default {
  name: 'CallPoliceTableColumn',
  components: {
    TableColumn
  },
  data() {
    return {
      dialogVisible:false,
      tableConfig:[],
      tableData:[],
      loading:false,
      flagval:''
    }
  },

  mounted() {
    
  },

  methods: {
    async tolook(row,flag){
      this.dialogVisible=true
      this.flagval={...row,title:flag}
      const {data:{list}}=flag=='day'? await getDayReportapi({companyId:row.companyId,yearMonth:row.yearMonth}):await getHourReportapi({companyId:row.companyId,yearMonth:row.yearMonth})
      this.tableConfig= [
        { label: '部门', prop: 'departmentName' ,'width':'160'},
        { label: '班组', prop: 'teamName' ,'width':'160'},
        { label: '人员', prop: 'personName' ,'minwidth':'120'},
      ]
      const obj=list.find(ele=>ele.workingHoursData)?.workingHoursData
      Object.keys(obj?obj:{}).map(ele=>{
        this.tableConfig.push( {
          label:ele,
          prop:ele
        })
      })
      this.tableData=list?.map(ele=>{
          return {
            ...ele,
            ...ele.workingHoursData,
          }
       })
    },
    exporttab(){
      const {companyId,yearMonth} =this.flagval
      exportexcel(
        this.flagval.title=='day'?'/ecm-microservice-biz/ecm/team/budget/energy/stats/day/report/exportExcel':
        '/ecm-microservice-biz/ecm/team/budget/energy/stats/hour/report/exportExcel',
        {companyId,yearMonth},
        this.flagval.title=='day'?'日预算电量':'小时预算电量'
      )
    }
  }
}
</script>
